package com.manopservice.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.manopservice.model.CarAutoPartType;


@Repository("carAutoPartTypeDAO")
public class CarAutoPartTypeDAOImpl implements CarAutoPartTypeDAO{

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void save(CarAutoPartType carAutoPartType) {
		sessionFactory.getCurrentSession().saveOrUpdate(carAutoPartType);
		
	}

	@Override
	public void delete(int id) {
		CarAutoPartType carAutoPartType = (CarAutoPartType) sessionFactory.getCurrentSession().get(CarAutoPartType.class, id);
		sessionFactory.getCurrentSession().delete(carAutoPartType);
		
	}

	@SuppressWarnings("unchecked")
	public List<CarAutoPartType> findAll() {
		
		return (List<CarAutoPartType>) sessionFactory.getCurrentSession().createCriteria(CarAutoPartType.class).list();
	}

	@Override
	public CarAutoPartType findById(int id) {

		return (CarAutoPartType) sessionFactory.getCurrentSession().get(CarAutoPartType.class, id);
	}

}
